<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录页面</title>
  <!-- 引入WeUI样式表 -->
  <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.0.1/weui.min.css">
  <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.0.1/weui.min.css">
  <!-- 引入 weui JS 库 -->
  <script src="https://res.wx.qq.com/open/libs/weuijs/1.2.1/weui.min.js"></script>
  <!-- 引入JQuery文件 -->
  <script src="https://cdn.bootcss.com/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div class="weui-cells__title">登录</div>
<div class="weui-cells weui-cells_form">
  <div class="weui-cell">
    <div class="weui-cell__hd"><label class="weui-label">用户名</label></div>
    <div class="weui-cell__bd">
      <input class="weui-input" type="text" name="username" placeholder="请输入用户名" />
    </div>
  </div>
  <div class="weui-cell">
    <div class="weui-cell__hd"><label class="weui-label">密码</label></div>
    <div class="weui-cell__bd">
      <input class="weui-input" type="password" name="password" placeholder="请输入密码" />
    </div>
  </div>
</div>
<div class="weui-btn-area">
  <a class="weui-btn weui-btn_primary" href="javascript:" id="login">登录</a>
</div>
</body>
<script>
  var ip="127.0.0.1";
  $(document).ready(function() {
    // 登录请求
    function login(username, password) {
      $.ajax({
        url: 'http://'+ip+':35948/gm/login',
        method: 'POST',
        data: {
        },
        success: function(data, textStatus, xhr) {
          console.log(JSON.stringify(data));
          if (data.status === true) { // 成功响应
            location.href = 'home.html?token='+data.token; // 跳转到主页
          }else{
            weui.alert("密码错误或者用户不存在!")
          }
        },
        error: function(xhr, textStatus, error) {
          console.log(xhr);
          if (xhr.status === 401) { // 未授权的响应
            weui.alert(xhr.responseJSON.message);
          }
        }
      });
    }

  });
</script>
</html>